<?php

namespace app\index\controller;

use app\index\model\PcSoftInfo;
use think\Controller;
use think\Db;
use think\Request;

class Search extends Controller
{

    protected $noNeedLogin = '*';
    protected $noNeedRight = '*';
    protected $layout = '';

    public function index()
    {
        $request = Request::instance();

        if($request->get('keyword')){
            $where['Name']      = ['like','%'.$request->get('keyword').'%'];
        }

        $limit            = $request->get('limit','100');
        $where['Status']    = ['=',PcSoftInfo::STATUS_1];
        // 查询分页数据
        $pc_soft_list = Db::name('pc_soft_info')->where($where)->order('id', 'desc')->paginate($limit);
        $pc_soft_list_data = Db::name('pc_soft_info')->where($where)->order('id', 'desc')->select();

        //如果搜索出来数据，记录关键词
        if($pc_soft_list_data && $request->get('keyword') != ''){
            foreach($pc_soft_list_data as $k=>$v){
                $data['key_words']      = $v['Name'];
                $data['soft_id']        = $v['id'];
                $data['soft_version']   = $v['Version'];
                $data['form_type']      = 1;
                $data['mac']            = '';
                $data['ip']             = $_SERVER['REMOTE_ADDR'];
                $data['system']         = getclientoperation();         //获取客户端系统信息
                $data['create_time']    = date('y-m-d H:i:s');
                Db::name('key_words')->insert($data);
            }
        }


        $this->assign('pc_soft_list',$pc_soft_list);
        return $this->view->fetch();
    }






}
